//
//  TimeRedNextView.swift
//  TianTianBiTing
//
//  Created by Gox mac 2 on 2019/3/4.
//  Copyright © 2019 Gox_WallyDiao. All rights reserved.
//

import UIKit

class TimeRedNextView: UIView {
    var redBlock:(() -> Void)?
    var priceStr:String = ""
    
    init(frame: CGRect, priceStr:String) {
        super.init(frame: frame)
        self.backgroundColor = UIColor.clear
        self.priceStr = priceStr
        setUI()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setUI() {
        self.isUserInteractionEnabled = true
        self.backgroundColor = RGB_Same(0, 0.88)
        
        let backImageView = UIImageView.init(frame: FRAME_CGFloat(SCREEN_WIDTH / 2 - 144, 70.5, 288, 310.5))
        backImageView.layer.cornerRadius = 10.5
        backImageView.layer.masksToBounds = true
        backImageView.image = IMAGE(name: "time_redBBack")
        self.addSubview(backImageView)
        backImageView.isUserInteractionEnabled = true
        
        let textlabel = UILabel.init(frame: FRAME_CGFloat(0, 67, 288, 24))
        textlabel.font = FONT(17)
        textlabel.textColor = RGB_Same(0)
        textlabel.textAlignment = .center
        backImageView.addSubview(textlabel)
        textlabel.text = "送你\(self.priceStr)听币 听越多赚越多！"
        
        let redImageView = UIImageView.init(frame: FRAME_CGFloat(SCREEN_WIDTH / 2 - 60, 177.5, 120, 120))
        redImageView.layer.masksToBounds = true
        redImageView.image = IMAGE(name: "time_redBack")
        self.addSubview(redImageView)
        
        let leftlabel = UILabel.init(frame: FRAME_CGFloat(0, 22, 60, 21.5))
        leftlabel.font = FONT(19)
        leftlabel.textColor = RGB(230, 67, 64)
        leftlabel.textAlignment = .right
        redImageView.addSubview(leftlabel)
        leftlabel.text = self.priceStr
        
        let rightLabel = UILabel.init(frame: FRAME_CGFloat(60, 30, 60, 11.5))
        rightLabel.font = FONT(10)
        rightLabel.textColor = RGB(230, 67, 64)
        rightLabel.textAlignment = .left
        redImageView.addSubview(rightLabel)
        rightLabel.text = "听币"
        
        let allImageView = UIImageView.init(frame: FRAME_CGFloat(22.5, 253, 243, 45.5))
        allImageView.layer.masksToBounds = true
        allImageView.image = IMAGE(name: "time_redCheck")
        backImageView.addSubview(allImageView)
        allImageView.isUserInteractionEnabled = true
        allImageView.addGestureRecognizer(UITapGestureRecognizer(target:self, action:#selector(redAction)))
        
        let button = UIButton(type: UIButton.ButtonType.custom)
        button.frame = FRAME_CGFloat(SCREEN_WIDTH / 2 - 15, 446.5, 30, 30)
        button.setImage(IMAGE(name: "time_redClose"), for: .normal)
        button.addTarget(self, action: #selector(closeAction), for: .touchUpInside)
        self.addSubview(button)
    }
    
    @objc func redAction() {
        redBlock?()
        self.removeFromSuperview()
    }
    
    @objc func closeAction() {
        self.removeFromSuperview()
        
    }

}
